package com.woniuxy.dudugua.service.impl;

import com.woniuxy.dudugua.entity.*;
import com.woniuxy.dudugua.mapper.*;
import com.woniuxy.dudugua.service.ProductOperationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 商品操作的业务层实现类
 */
@Service
public class ProductOperationServiceImpl implements ProductOperationService {
    @Resource
    private ProductMapper productMapper;
    @Resource
    private StoreMapper storeMapper;
    @Resource
    private ProductInfoMapper productInfoMapper;
    @Resource
    private ProductSkuMapper productSkuMapper;
    @Resource
    private ProductImagesMapper productImagesMapper;
    @Resource
    private ProductInfoImagesMapper productInfoImagesMapper;
    /**
     * 添加商品，返回一个商品对象
     * @param product
     * @return
     * @throws Exception
     */
    public Product addProduct(Product product) throws Exception {
        product.setStatus(1);
        product.setSales(0);
        String name = storeMapper.selectByPrimaryKey(product.getStoreId()).getName();
        product.setStoreName(name);
        productMapper.insert(product);
        return productMapper.selectByPrimaryKey(product.getId());
    }

    /**
     * 添加商品属性
     * @param productInfo
     * @throws Exception
     */
    public void addIntroduce(ProductInfo productInfo) throws Exception {
        productInfoMapper.insert(productInfo);
    }

    /**
     * 添加商品sku
     * @param productSku
     * @throws Exception
     */
    public void addSku(ProductSku productSku) throws Exception {
        productSkuMapper.insert(productSku);
    }

    /**
     * 添加商品图片
     * @param productImages
     * @throws Exception
     */
    public void addProductImage(ProductImages productImages) throws Exception {
        productImagesMapper.insert(productImages);
    }

    /**
     * 添加商品详情图片
     * @param
     * @throws Exception
     */
    public void addProductInfoImage(ProductInfoImages productInfoImages) throws Exception {
        productInfoImagesMapper.insert(productInfoImages);
    }
}
